using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using DAL;
using BUS;
using Utility;
public partial class Admin_Chitietsanpham : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Url.ToString().Contains("dangnhap.aspx") == false
&& Session["UserName"] == null)
            Response.Redirect("~/Admin/dangnhap.aspx");
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"]);
            tbSanpham sp = tbSanphamBUS.GetByID(id);
            lit_Ma.Text = sp.Masp.ToString();

            tbDoanhnghiep dn = tbDoanhnghiepBUS.GetByID(sp.Madn);
            lit_dn.Text = dn.Tendnghiep;

            tbDanhmuc dm = tbDanhmucBUS.GetByID(sp.Madmuc);
            lit_dm.Text = dm.Tendanhm;

            tbKhuvuc kv = tbKhuvucBUS.GetByID(sp.Makv);
            lit_kv.Text = kv.Tenkv;

            tbTrangthaisanpham ttsp = tbTrangthaisanphamBUS.GetByID(sp.Mattsp);
            lit_tt.Text = ttsp.Trangthai;


            lit_Tensp.Text = sp.Tensp;
            lit_ct.Text = sp.Mota;
            lit_giab.Text = sp.Giaban.ToString();
            lit_giag.Text = sp.Giagoc.ToString();
            lit_sl.Text = sp.Soluong.ToString();
            lit_hsd.Text = sp.Hansudung.ToString();
            lit_tgbd.Text = sp.Thoigianbd.ToString();
            lit_tgkt.Text = sp.Thoigiankt.ToString();
            lit_dk.Text = sp.Dieukien.ToString();
            lit_tlck.Text = sp.Tilechietkhau.ToString() + " %";
            img_bando.ImageUrl = "~/Hinhanh/Hinh/" + sp.Bando;
            img_hmh.ImageUrl = "~/Hinhanh/Hinh/" + sp.Hinhchinh;

            hyperlinkPager.PageSize = 5;
            Criteria c = new Criteria();
            c.add(Condition.AND, tbSanphamColumn.Masp, Condition.EQUAL, id);
            int total = 0;
            tbHinhsanphamCollection haCollection =
             tbHinhsanphamBUS.Get(c.Criter, hyperlinkPager.CurrentIndex, hyperlinkPager.PageSize,
                tbHinhsanphamColumn.Masp.ToString(), OrderDirection.ASC.ToString(), out total);
            Repeater1.DataSource = haCollection;
            Repeater1.DataBind();
            hyperlinkPager.ItemCount = total;

        }
        catch
        {
            Response.Redirect("~/Admin/Danhsachsanpham.aspx");
        }
    }
       
        //protected void hyperlinkPager_Command(object sender, CommandEventArgs e)
        //{
        //    //hyperlinkPager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        //    //LoadData();
        //}
     protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
         e.Item.ItemType == ListItemType.Item)
        {
            tbHinhsanpham ha = (tbHinhsanpham)e.Item.DataItem;
            
            Image img_hinhanh = (Image)e.Item.FindControl("hinh");

            img_hinhanh.ImageUrl = "~/Hinhanh/" + ha.Tenhinh;

        }
    }
}
//}

